package com.hertz.alarm.service.impl;

import java.io.Serializable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hertz.alarm.dao.AbstractEntity;
import com.hertz.alarm.service.EntityService;
@Service
public class EntityServiceImpl extends BaseServiceImpl  implements EntityService {
	private Logger logger = LoggerFactory.getLogger(EntityServiceImpl.class);
	@Override
	public <T extends AbstractEntity<ID>, ID extends Serializable> T getById(
			ID id, Class<T> clazz) {
		return getUnCacheById(id, clazz);
	}

	@Override
	public <T extends AbstractEntity<ID>, ID extends Serializable> T getUnCacheById(
			ID id, Class<T> clazz) {
		logger.debug("getById id:{},class:{}",id.toString(),clazz.getSimpleName());
		T t = baseDAO.get(id, clazz);
        logger.debug("load from db:{}",t!=null);
		return t;
	}

	@Override
	public <T extends AbstractEntity<ID>, ID extends Serializable> T save(T t) {
		baseDAO.saveOrUpdate(t);
		return t;
	}

	@Override
	public <T extends AbstractEntity<ID>, ID extends Serializable> T update(T t) {
		// TODO Auto-generated method stub
		baseDAO.update(t);
		return t;
	}

	@Override
	public <T extends AbstractEntity<ID>, ID extends Serializable> ID delete(T t) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T extends AbstractEntity<ID>, ID extends Serializable> void delete(
			ID id, Class<T> clazz) {
		// TODO Auto-generated method stub
		baseDAO.delete(id, clazz);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
